#!/bin/bash
# 如果没有设置端口号,则退出
if [ -z "$1" ]; then
    echo "请输入要设置的端口号"
    exit 1
fi
# 下载jdk17 因为jenkins在jdk17时,安装插件会成功
if [ -e "jdk-17_linux-x64_bin.tar.gz" ]; then
    echo "jdk-17_linux-x64_bin.tar.gz 已存在,无需重复下载"
  else
     wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
fi

if [ -d "jdk-17" ]; then
    echo "jdk-17 已存在,无需重复解压"
  else
    tar -xzvf jdk-17_linux-x64_bin.tar.gz
    mv jdk-17_linux-x64_bin jdk-17
fi



if [ -e "jenkins.war" ]; then
    echo "jenkins.war 目录已存在,无需重复创建"
  else
    # 下载jenkins.war
    wget https://mirrors.jenkins.io/war-stable/2.361.1/jenkins.war --no-check-certificate
    echo "jenkins.war 下载成功"
fi

echo "开始启动jenkins"

nohup java -jar jenkins.war --serverPort=$1 > jenkins.log 2>&1 &
echo "启动成功,启动日志请查看jenkins.log"